package forms
{
	import spark.components.List;

	public class Utils
	{
		import mx.collections.ArrayList;
		include "../filters/colorTransformations.as";

		
		public static var GibInfo:ArrayList = new ArrayList();
		public static var listObj:List = new List();
		
		public function Utils()
		{
		}
		
		public static function addFav(uID):void
		{
			
		}
		
		var deadline:Number;
		var startdDate:Number;
		var returnDate:Number; // or DateChooser
		var timeLeft:Number;
		
		//seconds
		var min:Number=60;
		var hour:Number=3600;
		var day:Number=86400;
		var week:Number=604800;
		var year:Number=31449600;
		
		//timelog
		var yy:Number;
		var ww:Number;
		var dd:Number;
		var hh:Number;
		var mm:Number;
		var ss:Number;
		var hoursStr:String;
		var minutesStr:String;
		var secondsStr:String;
		public var openPopUp:Boolean = false;
		public var extDate = false;
		
		
		public var _model:Array = new Array();
		
		
		public function timeRemain(newDate:Object,past=false)
		{
			if(extDate!=false)
				newDate = extDate;
			
			var dmap:Date = new Date();
			var startDate = dmap.getTime();
			var defaultDate = {y:2011,m:0,d:10};
			var y = Number(newDate.year)==NaN?Number(newDate.fullYear):Number(newDate.year);
			var m = Number(newDate.month-1);
			var d = Number(newDate.day);
			var hh = Number(newDate.hour);
			var mm = Number(newDate.minutes);
			var ss = Number(newDate.seconds);
			
			//trace(y,m,d,hh,mm,ss);
			var futureDate:Date = new Date(y,m,d,hh,mm,ss);
			deadline = futureDate.getTime();
			
			//	trace(dmap.getTime()+"--"+futureDate.getTime());
			
			var FinalStr;
			
			if(past)
				timeLeft = Math.round((startDate - deadline)/1000);
			else
			{
				//calculate time reamining
				timeLeft = Math.round((deadline - startDate)/1000); // return seconds remaining.
			}
			
			ss = timeLeft>0?timeLeft:0;
			mm = ss>60?Math.floor(timeLeft/60):0;
			hh = mm>60?Math.floor(timeLeft/3600):0;
			
			secondsStr = ss<9?"0"+ss:String(ss%60);
			minutesStr = mm<9?"0"+mm:String(mm%60);
			hoursStr   = hh<9?"0"+hh:String(hh);
			
			var days = hh>24?Math.round(hh/24):"";
			var months = days>30?Math.round(days/30):"";
			var years = months>12?Math.round(months/12):"";
			
			if(past)
				return FinalStr = {years:years,months:months,days:days,hours:hh,minutes:mm,time:years+" "+months+" "+days+" "+hoursStr+" καί "+(Number(minutesStr)%60)};
			return FinalStr = hoursStr+":"+minutesStr+":"+secondsStr;
		}
		
		
		function CountBackwards()
		{
			if(ss != 0){
				ss--;
			}
			if(ss == 0 && mm > 0){
				mm--;
				ss = 59;
			}
			if(mm == 0  && hh > 0){
				hh--;
				mm = 59;
			}
			if(hh == 0 && dd > 0){
				dd--;
				hh = 23;
			}
			if(dd == 0 && ww > 0){
				ww--;
				dd = 6;
			}
			if(ww == 0 && yy > 0){
				yy--;
				ww = 51;
			}
			return yy + ":" + ww + ":" + dd + ":" + hh + ":" + mm + ":" + ss;
		}
		
		
		//returns a number in the specified range
		public function randomRange(minNum:Number=0, maxNum:Number=11):Number
		{
			return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
		}
		
	}
}